package data;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import database.ConnectionHandler;

public class HashedCard
{
    private String _data;
    public static Object lock = new Object();

    public HashedCard( String data )
    {
        _data = data;
        storeVote();
    }

    public boolean storeVote()
    {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat( DATE_FORMAT_NOW );
        String dateString = sdf.format( cal.getTime() );
        String sql = "INSERT INTO \"codedVotes\"(data, time) values('" + _data + "', '" + dateString + "')";
        try
        {
            ConnectionHandler connhandler = new ConnectionHandler();
            java.sql.Statement stmt = connhandler.getConnection().createStatement();
            stmt.executeUpdate( sql );
            connhandler.closeConnection();
            return true;
        }
        catch( Exception e )
        {
            System.out.println( e );
            return false;
        }
    }

    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
}
